App({
  onLaunch (options) {
    
  },

  login () {
    var that = this;
    return new Promise(function (resolve, reject) {
        if (wx.getStorageSync('token')) {
            resolve(wx.getStorageSync('token'))
        } else {
            wx.login({
                success: function (res) {
                    if (res.code) {
                        wx.request({
                            url: that.baseApiUrl + 'token/create',
                            header: {
                                'version': that.globalData.version
                            },
                            data: {code: res.code},
                            method: 'POST',
                            success: function (e) {
                                if (e.statusCode == 200) {
                                    wx.setStorageSync('token', e.data.token);
                                    resolve(e.data.token)
                                }
                            },
                            fail: () => {

                            }
                        })
                    } else {
                        console.log('登录失败！' + res.errMsg)
                    }
                }
            });
        }
        })
  },
   //baseApiUrl:"http://www.ydcrm.com/api/v1.",
   baseApiUrl:"https://gx.52document.com/api/v1.",
   globalData:{version:'v1'}

})